package com.mind.core.net.msg;

import io.netty.channel.Channel;

import java.io.UnsupportedEncodingException;

import com.mind.core.net.model.Connector;
import com.mind.core.net.model.IConnector;


/**
 * Flash Policy请求
 * 
 * 
 * 
 */
@SuppressWarnings("unchecked")
public class PolicyMessage extends BaseMessage {
	private String policy;

	public boolean readImpl() {
		int times = 20;
		byte b = readByte();
		while (b != 0 && times > 0) {
			b = readByte();
			times--;
		}
		return true;
	}

	public boolean write() throws MessageParseException {
		return writeImpl();
	}

	public boolean writeImpl() {
		try {
			byte[] bytes = policy.getBytes("gbk");
			writeBytes(bytes);
			writeByte((byte)0);
			return true;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return false;
		}
	}

	public byte getHandlerType() {
		return 12;
	}

	public String getMessageName() {
		return "CS_POLICY";
	}

	public String getPolicy() {
		return policy;
	}

	public void initPolicy() {
		this.policy = "--0-0-0-";
	}

	@Override
	public short getMessageType() {
		return 1;
	}

	@Override
	public void setSender(IConnector player) {
	}

	@Override
	public IConnector sender() {
		// TODO Auto-generated method stub
		return null;
	}

}